<template>
  <div>
    <!-- <div class="qup-page-heade bread-box">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item class="btn-green" @click.native="goBack">开业管理</el-breadcrumb-item>
        <el-breadcrumb-item>详情</el-breadcrumb-item>
      </el-breadcrumb>
      <div>
        <el-button size="mini" @click.native="goBack">返回</el-button>
      </div>
    </div> -->
    <div v-loading="dataLoading">
      <!-- 门店信息 -->
      <store-info :const-code="detailData.constCode" style="margin-top:20px" />
      <c-section title="开业推广明细">
        <c-list :column="3">
          <c-list-item label="开业广告支持金额" suffix="元" :value="detailData.advertAmount" />
          <c-list-item label="开业广告支持范围" dict-type-code="ADVERT_AMOUNT_RANGE" :value="detailData.advertAmountRange" />
          <c-list-item label="计划开业活动开始日期" :value="detailData.planActivityStartTime" />
          <c-list-item label="计划开业活动截止日期" :value="detailData.planActivityEndTime" />
          <c-list-item label="实际开业活动开始日期" :value="detailData.actualActivityStartTime" />
          <c-list-item label="实际开业活动截止日期" :value="detailData.actualActivityEndTime" />
          <c-list-item type="textarea" :span="3" label="活动主题" :value="detailData.activityTheme" />

        </c-list>
      </c-section>
      <div class="qup-title-box"><span class="border" /><span>附件管理</span></div>
      <table-box
        ref="refDesignFile"
        :table-config="fileDataConfig"
        :table-height="400"
        :data="fileDataList"
        show-index
      />
      <!-- 图片预览 -->
      <el-image-viewer
        v-if="imgDialogVisible"
        :on-close="handleCloseImg"
        :url-list="[previewImg]"
      />
    </div>
  </div>
</template>
<script>
import storeInfo from './storeInfo.vue'
import BackPageMixin from '@/mixins/backPage'
import { getShopAttachment } from '@/api/common.js'
import { getDetailById } from '@/api/shopOpenManage'
import ElImageViewer from 'element-ui/packages/image/src/image-viewer'
import { filterURL } from '@/utils'

export default {
  name: 'OpenDetail',
  components: { storeInfo, ElImageViewer },
  mixins: [BackPageMixin],
  props: {
    // id: {
    //   type: String,
    //   default: ''
    // }
  },
  data() {
    return {
      id: '',
      previewImg: '',
      imgDialogVisible: false,
      fileDataList: [], // 附件列表信息
      dataLoading: false,
      detailData: { },
      fileDataConfig: {
        hideFuncBar: true,
        tabIndex: 0,
        // 表格字段动态配置
        setting: [
          {
            prop: 'attachmentType',
            label: '附件类型',
            minWidth: '140'
          },
          {
            prop: 'attachmentName',
            label: '附件名称',
            minWidth: '140'
          },
          {
            prop: 'createBy',
            label: '创建人',
            minWidth: '140'
          },
          {
            prop: 'createTime',
            label: '上传时间',
            minWidth: '140'
          },
          {
            label: '操作',
            button: [
              {
                name: '预览',
                clickFun: this.handlePreview,
                className: 'table-handelclick-text',
                type: 'text'
              },
              {
                name: '下载',
                clickFun: this.handleDownload,
                className: 'table-handelclick-text',
                type: 'text'
              }
            ]
          }]
      },
      formData: {}
    }
  },
  created() {
    this.id = this.$route.query.id
    if (this.id) {
      this.dataLoading = true
      this.getFiles()// 获取文件列表信息
      getDetailById(this.id).then(res => {
        if (res.success === 1) {
          this.detailData = res.data
          this.dataLoading = false
        }
      })
    }
  },
  methods: {
    handleDownload(file) {
      const a = document.createElement('a')
      const url = `/pdf-file/` + file.attachmentUrl
      const fileName = file.attachmentName
      a.href = url
      a.download = fileName
      a.click()
    },
    handlePreview(file) {
      const fileExtension = file.attachmentUrl.substring(file.attachmentUrl.lastIndexOf('.') + 1).toLowerCase()
      if (fileExtension === 'pdf') {
        // pdf预览
        const url = `/pdf-file/` + file.attachmentUrl
        const routeData = this.$router.resolve({
          path: '/viewFile',
          query: {
            src: btoa(url)
          }
        })
        window.open(routeData.href, '_blank')
      } else if (fileExtension === 'jpg' || fileExtension === 'jpeg' || fileExtension === 'png') {
      // 图片预览
        this.imgDialogVisible = true
        this.previewImg = filterURL(file.attachmentUrl)
      } else if (fileExtension === 'doc' || fileExtension === 'docx' || fileExtension === 'xlsx' || fileExtension === 'excel') {
        // word,excel预览
        window.open('http://oos.quanyou.com.cn/op/view.aspx?src=' + filterURL(file.attachmentUrl))
      } else {
        this.$message.warning('该文件类型不支持预览')
      }
    },
    handleCloseImg() {
      this.imgDialogVisible = false
    },
    // 获取附件
    getFiles() {
      getShopAttachment(this.id).then(res => {
        this.fileDataList = res.data
      })
    }
  }
}
</script>
<style lang="scss" scoped>
/deep/ .el-breadcrumb__inner{
    color: $qup-color-primary;
  }
</style>
